/**
 * 路由初始化
 * @module router/index
 */
import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index'
import routes from './routes'

const router = new Router(routes)

const NAV_STORE_NAME = 'nav-tabs'
const vue = new Vue()
router.beforeEach((to, from, next) => {
  if (to.meta.tab) { // 在tab展示
    vue.$nextTick(() => {
      store.commit({
        type: `${NAV_STORE_NAME}/push`,
        tab: { label: to.name, name: to.path, closable: true }
      })
    })
  }
  next()
});

Vue.use(Router)

export default router
